using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using Lizk.WebScraper;

namespace AnimeScrapers
{
    [XmlRoot]
    [Serializable]
    public class AnimeResult : ScraperResult
    {
        public AnimeResult(string id)
            : base(id)
        {
        }
        public AnimeResult() { }

        private List<string> alternativeTitles = new List<string>();

        public List<string> AlternativeTitles
        {
            get { return alternativeTitles; }
        }

        private List<string> makers = new List<string>();

        public List<string> Makers
        {
            get { return makers; }
        }

        public Episode GetEpisode(int episode)
        {
            foreach (Episode e in Episodes)
            {
                try
                {
                    int ep = Convert.ToInt32(e.EpisodeNumber);
                    if (ep == episode)
                        return e;
                }
                catch
                {
                    continue;
                }
            }
            return null;
        }


        private int parts;

        public int Parts
        {
            get { return parts; }
            set { parts = value; }
        }

        private string type;

        public string Type
        {
            get { return type; }
            set { type = value; }
        }


        public override string ShortDescription
        {
            get
            {
                string g = title;
                if (year > 0)
                    g += " (" + year + ")";

                if (alternativeTitles.Count > 0)
                {
                    g += " aka: ";
                    string s = "";
                    for (int i = 0; i < alternativeTitles.Count && i < 2; i++)
                    {
                        if (s != "")
                            s += ", ";
                        s += alternativeTitles[i];
                    }
                    
                    g += s;
                }

                return g;
//                return title + (year > 0 ? " (" + year + ")" : "") + (Type != null ? " (" + type + ")" : "");
            }
        }

        private string url;

        public string Website
        {
            get { return url; }
            set { url = value; }
        }
        /*
        [XmlRoot]
        [XmlInclude(typeof(AnimeFile))]
        public class Episode
        {
            private List<AnimeFile> files = new List<AnimeFile>();

            public List<AnimeFile> Files
            {
                get { return files; }
            }
            private string title;

            public string Title
            {
                get { return title; }
                set { title = value; }
            }
            private string episodeNr;

            public string EpisodeNumber
            {
                get { return episodeNr; }
                set { episodeNr = value; }
            }
            private int runningTime;

            public int RunningTime
            {
                get { return runningTime; }
                set { runningTime = value; }
            }

            private DateTime date;

            public DateTime Date
            {
                get { return date; }
                set { date = value; }
            }


        }
        [XmlRoot]
        public class AnimeFile
        {
            private long fileSize;

            public long FileSize
            {
                get { return fileSize; }
                set { fileSize = value; }
            }

            private string encoder;

            public string Encoder
            {
                get { return encoder; }
                set { encoder = value; }
            }
            private string resolution;

            public string Resolution
            {
                get { return resolution; }
                set { resolution = value; }
            }
            private string source;

            public string Source
            {
                get { return source; }
                set { source = value; }
            }


        }*/

        public override string Description
        {
            get
            {
                string info = ShortDescription + "\n";
                if (!string.IsNullOrEmpty(Type))
                    info += "Type - " + Type + "\n";
                if (Makers.Count > 0)
                {
                    info += "Maker" + (Makers.Count > 1 ? "s" : "") + " - ";
                    string g = "";
                    foreach (string maker in Makers)
                    {
                        if (g != "")
                            g += ", ";
                        g += maker;
                    }
                    info += g;
                    info += "\n";
                }

                if (Genres.Count > 0)
                    info += "Genre" + (Genres.Count > 1 ? "s" : "") + " - " + String.Join(", ", Genres.ToArray()) + " \n";
                if (Rating != 0)
                    info += "Rating - " + Rating + "\n";
                if (Parts != 0)
                    info += (type != "TV Series" ? "Parts" : "Episodes") + " - " + Parts + "\n";
                if (!string.IsNullOrEmpty(Website))
                    info += "Website - " + Website + "\n";
                if (!string.IsNullOrEmpty(Summary))
                    info += "Summary - " + Summary + "\n";
                return info;
            }
        }
        /*
        public override string Description
        {
            get
            {
                return ShortDescription + Environment.NewLine +
                        (string.Join(", ", genres.ToArray())) + Environment.NewLine +
                        "Rating - " + rating + Environment.NewLine +
                        "Summary - " + summary;
            }
        }*/
    }

}
